home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
amos
/
intuiextend16.lha
/
bonus
/
easylife
/
demos
/
VarChecker.AMOS
/
VarChecker.amosSourceCode
Wrap
AMOS Source Code
|
1992-02-26
|
17KB
|
541 lines
'****************************************************************************
'** Variable Checker V1.0 - By Paul Hickman (ph@doc.ic.ac.uk) **
'** **
'** Requires AMOS Pro & Easylife V1.4+ Distributed as an easylife demo **
'****************************************************************************
Set Accessory
'
'MXVARS is the maximum number of variable names in your program
'NUMCOMMANDS is the number of commands which may be confused with
'variable names (See Line 34).
'
Set Buffer 80
MXVARS=300 : NUMCOMMANDS=6
'
Dim NAME$(MXVARS,1),NAME(MXVARS,4),TYPE$(4),COMMAND$(NUMCOMMANDS)
Global AL$,NAME$(),NAME(),LAST,GLO,SHA,LOC,FLP,COMMAND$()
'NAME(N,0)=Type (See Below)
'NAME(N,1)=Number of local uses.
'NAME(N,2)=Number of global assignments.
'NAME(N,3)=Number of global references.
'NAME(N,4)=Line Number of definition.
'
GLO=1 : TYPE$(1)="Global"
SHA=2 : TYPE$(2)="Shared"
LOC=3 : TYPE$(3)="Local"
FLP=4 : TYPE$(4)="For Loop"
LAST=0
For A=1 To NUMCOMMANDS : Read COMMAND$(A) : Next
'************************************************************************
'These are the commands to ignore - Set NUMCOMANDS at the top of the code
'to the number of them.
Data "Scene X","Scene Y","Imouse X","Imouse Y","Jd Char X","Jd Char Y"
'************************************************************************
INIT_SCREEN
' Make sure we are an accessory
If Prg Under<>1
If Exist("VarChecker.Doc")
Read Text "VarChecker.Doc"
Else
NULL=Dialog Box(AL$,1,"This program must be run as an accessory!")
End If
MN_QUIT
End If
' Initialise Program Listing
'
TITLE
Clear Key
' Open all procedures
Call Editor 89 : Rem Equ("AEd_UnfoldAll")
' Ask number of lines
Ask Editor 5 : NLINES=Param : Rem Equ("AEdAsk_NumberOfLines")
' Top of text
Call Editor 17 : RemEqu("AEd_TopOfText")
SCOPE$="MAIN PROGRAM"
For N=1 To NLINES
Ask Editor 1,N : LINE$=Param$ : Rem Equ("AEdAsk_CurrentLine")
SP= Extension_16_00C8(LINE$,32)
LINE$=Mid$(LINE$,SP)
If Left$(LINE$,7)="Shared "
_DECLARE[Mid$(LINE$,8),SCOPE$,SHA,N,False]
End If
Next
For N=1 To NLINES
'Read the current line
Ask Editor 1,N : LINE$=Param$ : Rem Equ("AEdAsk_CurrentLine")
'Ignore whole line comments
SP= Extension_16_00C8(LINE$,32)
LINE$=Mid$(LINE$,SP)
If(SP>0) and(Asc(LINE$)<>39)
'Replace all quoted strings with 0.
Repeat
A1= Extension_16_00AA(LINE$,"'") : If A1=0 : A1=Len(LINE$)+1 : End If
A2= Extension_16_00AA(LINE$,'"') : If A2=0 : A2=Len(LINE$)+1 : End If
A=Min(A1,A2)
If A<Len(LINE$)+1
If A=A1
AA= Extension_16_00BC(LINE$,"'",A)
Else
AA= Extension_16_00BC(LINE$,'"',A)
End If
If AA
LINE$=Left$(LINE$,A-1)+"0"+Mid$(LINE$,AA+1)
Else
LINE$=Left$(LINE$,A-1)
End If
End If
Until A=Len(LINE$)+1
'Check for procedure definition
If Left$(Upper$(LINE$),9)="PROCEDURE"
'Get procedure name for scope of local variables
P= Extension_16_008C(LINE$,91)
If P
SCOPE$=Mid$(LINE$,11,P-11)
Else
SCOPE$=Mid$(LINE$,11)
End If
'Record declaration of parameters as local variables
_DECLARE[Mid$(LINE$,P+1,Len(LINE$)-P-1),SCOPE$,LOC,N,False]
Else If Left$(LINE$,8)="End Proc"
'Pass End Proc's argument string for references
If Mid$(LINE$,9,1)="["
PARSE_ARGS[Mid$(LINE$,10,Len(LINE$)-10),SCOPE$,False,N]
End If
'Scan for local variables/parameters were not refered to, and
'shared variables that were not refered to, or set to a value.
A=0 : While A<LAST
If NAME$(A,1)=SCOPE$
If NAME(A,1)=0
If NAME(A,0)=LOC
'Allow NULL to be unreferenced
If(NAME$(A,0)<>"NULL") and(NAME$(A,0)<>"NULL#") and(NAME$(A,0)<>"NULL$")
DLOG["Unreferenced Local Variable: "+NAME$(A,0)]
End If
Else
If NAME(A,0)=SHA
DLOG["Unused Shared Variable: "+NAME$(A,0)]
End If
End If
End If
If NAME(A,0)>=LOC
'Remove all local/for loop variables from array
For AA=A To LAST+1
For XX=0 To 4 : NAME(AA,XX)=NAME(AA+1,XX) : Next
NAME$(AA,0)=NAME$(AA+1,0)
NAME$(AA,1)=NAME$(AA+1,1)
Next
Dec LAST
Else
NAME(A,1)=0
Inc A
End If
Else
Inc A
End If
Wend
'Change scope to outside procedure
SCOPE$="MAIN PROGRAM"
Else If Left$(LINE$,7)="Shared "
'Record declaration of shared variables
_DECLARE[Mid$(LINE$,8),SCOPE$,SHA,N,False]
Else If Left$(LINE$,7)="Global "
'Record declaratino of global variables
_DECLARE[Mid$(LINE$,8),SCOPE$,GLO,N,False]
Else
'Splitup the line into it's statements, and parse each in turn.
While LINE$<>""
Exit If Left$(LINE$,4)="Rem "
SEP= Extension_16_00AA(LINE$,":")
If SEP
STATE$=Left$(LINE$,SEP-2)
LINE$=Mid$(LINE$,SEP+2)
Else
STATE$=LINE$ : LINE$=""
End If
'
PARSE_STAT[STATE$,N,False]
Wend
End If
End If
'Move to the next line of program source.
Call Editor 2 : Rem Equ("AEd_Down")
Next
For A=0 To LAST
If(NAME$(A,0)<>"") and(NAME(A,0)<>FLP) and(NAME$(A,0)<>"NULL") and(NAME$(A,0)<>"NULL#") and(NAME$(A,0)<>"NULL$")
If(NAME(A,2)=0) and(NAME(A,3)=0)
Call Editor 76,NAME(A,4)
DLOG["Unused "+TYPE$(NAME(A,0))+" Variable: "+NAME$(A,0)]
Else If(NAME(A,2)=0) and(NAME(A,0)<>LOC)
Call Editor 76,NAME(A,4)
DLOG["Undefined "+TYPE$(NAME(A,0))+" Variable: "+NAME$(A,0)]
Else If NAME(A,3)=0
Call Editor 76,NAME(A,4)
T$=TYPE$(NAME(A,0))
If(NAME(A,0)=LOC) and(NAME$(A,1)="MAIN PROGRAM") : T$="Main Program" : End If
DLOG["Unreferenced "+T$+" Variable: "+NAME$(A,0)]
End If
End If
Next
NULL=Dialog Box(AL$,1,"Scan completed. No more undeclared or unreferenced variables")
MN_QUIT
Procedure INIT_SCREEN
'Generates code to draw requesters.
Restore ALT
Repeat
Read A$ : AL$=AL$+A$
Until A$=""
For A=1 To 7 : Trap Screen Close A : Next
Resource Screen Open 0,640,40,0
Curs Off : Flash Off : Cls 0
Screen Display 0,,60,,
Wait Vbl
Paper 0 : Pen 1
Pop Proc
' QUICK RUN DIALOG BOXES
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ALT: Data " "
' One button, CANCEL
' ~~~~~~~~~~~~~~~~~~
Data "SIze SW,SH;"
Data "BAse SWidth SX -2/,SHeight SY- 2/;"
Data "IF 0VA 0=;"
Data "["
Data "BOx 0,0,1,SX,SY;"
Data "POut 1VACX,16,1VA,0,7;"
Data "BU 0,0,0,SX,SY,0,0,0;[][SM;]"
Data "]"
Data "IF 0VA 1=;"
Data "["
Data "BOx 0,0,1,SX,SY;"
Data "POut 1VACX,8,1VA,0,7;"
Data "BU 1,SX112-,SY16-,96,16,0,0,1;[LI 0,0,41BP3*+,SX;PR 'Quit' CXBP+,1,'Quit',7;][BR0;BQ;]"
Data "KY 27,0;"
Data "BU 0,0,0,SX,SY,0,0,0;[][SM;]"
Data "RUn 0,3;"
Data "]"
Data "IF 0VA 2=;"
Data "["
Data "BOx 0,0,1,SX,SY;"
Data "POut 1VACX,8,1VA,0,7;"
Data "BU 1,16,SY16-,96,16,0,0,1;[LI 0,0,41BP3*+,SX;PR 'Continue'CXBP+,1,'Continue',7;][BR0;BQ;]"
Data "KY 13,0;"
Data "BU 2,SX112-,SY16-,96,16,0,0,1;[LI 0,0,41BP3*+,SX